package com.bll;

import java.util.ArrayList;

import com.dal.DefectTypeDAO;
import com.model.DefectType;

public class DefectTypeBLO {
	
	public enum DefectTypeEnum {
		Coding(1), Syntax(2);

		private final int id;

		DefectTypeEnum(int i) {
			id = i;
		}

		DefectTypeEnum parse(int i) throws Exception {
			for (DefectTypeEnum e : DefectTypeEnum.values()) {
				if (e.id == id) {
					return e;
				}
			}
			return null;
		}
	}
	/*
	 * Properties
	 */
	private int defectTypeId;
	private String defectTypeName;

	public DefectTypeBLO(int typeId, String typeName) {
		super();
		this.defectTypeId = typeId;
		this.defectTypeName = typeName;
	}

	// Methods

	public static ArrayList<DefectTypeBLO> loadAllDefectType() {
		ArrayList<DefectType> list = new DefectTypeDAO().select();
		return getDefectTypeBLOListFromEntityList(list);
	}

	// Internal Methods
	private static ArrayList<DefectTypeBLO> getDefectTypeBLOListFromEntityList(
			ArrayList<DefectType> list) {
		ArrayList<DefectTypeBLO> DefectTypeBLOlist = new ArrayList<DefectTypeBLO>();
		for (DefectType DefectType : list) {
			DefectTypeBLOlist.add(getDefectTypeBLOFromEntity(DefectType));
		}
		return DefectTypeBLOlist;
	}

	private static DefectTypeBLO getDefectTypeBLOFromEntity(DefectType entity) {
		return new DefectTypeBLO(entity.getDefectTypeID(), entity.getDefectTypeName());
	}

	// Utility Methods
	public String getDisplayText() {
		return defectTypeName;
	}

	/**
	 * @return the DefectTypeId
	 */
	public int getDefectTypeId() {
		return defectTypeId;
	}

	/**
	 * @param DefectTypeId
	 *            the DefectTypeId to set
	 */
	public void setDefectTypeId(int DefectTypeId) {
		this.defectTypeId = DefectTypeId;
	}

	/**
	 * @return the DefectTypeName
	 */
	public String getDefectTypeName() {
		return defectTypeName;
	}

	/**
	 * @param DefectTypeName
	 *            the DefectTypeName to set
	 */
	public void setDefectTypeName(String DefectTypeName) {
		this.defectTypeName = DefectTypeName;
	}

}
